home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
X User Tools
/
X User Tools (O'Reilly and Associates)(1994).ISO
/
sun4c
/
archive
/
tcltk.z
/
tcltk
/
man
/
cat3
/
CrtErrHdlr.3
< prev
next >
Wrap
Text File
|
1994-09-20
|
9KB
|
265 lines
Tk_CreateErrorHandler(3T)k Library Procedures
_________________________________________________________________
NAME
Tk_CreateErrorHandler, Tk_DeleteErrorHandler - handle X pro-
tocol errors
SYNOPSIS
#include <tk.h>
Tk_ErrorHandler
Tk_CreateErrorHandler(_d_i_s_p_l_a_y, _e_r_r_o_r, _r_e_q_u_e_s_t, _m_i_n_o_r, _p_r_o_c, _c_l_i_e_n_t_D_a_t_a)
Tk_DeleteErrorHandler(_h_a_n_d_l_e_r)
ARGUMENTS
Display *_d_i_s_p_l_a_y (in) Display whose
errors are to be
handled.
int _e_r_r_o_r (in) Match only error
events with this
value in the
_e_r_r_o_r__c_o_d_e field.
If -1, then match
any _e_r_r_o_r__c_o_d_e
value.
int _r_e_q_u_e_s_t (in) Match only error
events with this
value in the
_r_e_q_u_e_s_t__c_o_d_e field.
If -1, then match
any _r_e_q_u_e_s_t__c_o_d_e
value.
int _m_i_n_o_r (in) Match only error
events with this
value in the
_m_i_n_o_r__c_o_d_e field.
If -1, then match
any _m_i_n_o_r__c_o_d_e
value.
Tk_ErrorProc *_p_r_o_c (in) Procedure to invoke
whenever an error
event is received
for _d_i_s_p_l_a_y and
matches _e_r_r_o_r,
_r_e_q_u_e_s_t, and _m_i_n_o_r.
NULL means ignore
any matching
errors.
Tk 1
Tk_CreateErrorHandler(3T)k Library Procedures
ClientData _c_l_i_e_n_t_D_a_t_a (in) Arbitrary one-word
value to pass to
_p_r_o_c.
Tk_ErrorHandler _h_a_n_d_l_e_r (in) Token for error
handler to delete
(return value from
a previous call to
Tk_CreateErrorHandler).
_________________________________________________________________
DESCRIPTION
Tk_CreateErrorHandler arranges for a particular procedure
(_p_r_o_c) to be called whenever certain protocol errors occur
on a particular display (_d_i_s_p_l_a_y). Protocol errors occur
when the X protocol is used incorrectly, such as attempting
to map a window that doesn't exist. See the Xlib documenta-
tion for XSetErrorHandler for more information on the kinds
of errors that can occur. For _p_r_o_c to be invoked to handle
a particular error, five things must occur:
[1] The error must pertain to _d_i_s_p_l_a_y.
[2] Either the _e_r_r_o_r argument to Tk_CreateErrorHandler must
have been -1, or the _e_r_r_o_r argument must match the
_e_r_r_o_r__c_o_d_e field from the error event.
[3] Either the _r_e_q_u_e_s_t argument to Tk_CreateErrorHandler
must have been -1, or the _r_e_q_u_e_s_t argument must match
the _r_e_q_u_e_s_t__c_o_d_e field from the error event.
[4] Either the _m_i_n_o_r argument to Tk_CreateErrorHandler must
have been -1, or the _m_i_n_o_r argument must match the
_m_i_n_o_r__c_o_d_e field from the error event.
[5] The protocol request to which the error pertains must
have been made when the handler was active (see below
for more information).
_P_r_o_c should have arguments and result that match the follow-
ing type:
typedef int Tk_ErrorProc(
ClientData _c_l_i_e_n_t_D_a_t_a,
XErrorEvent *_e_r_r_E_v_e_n_t_P_t_r);
The _c_l_i_e_n_t_D_a_t_a parameter to _p_r_o_c is a copy of the _c_l_i_e_n_t_D_a_t_a
argument given to Tcl_CreateErrorHandler when the callback
was created. Typically, _c_l_i_e_n_t_D_a_t_a points to a data struc-
ture containing application-specific information that is
needed to deal with the error. _E_r_r_E_v_e_n_t_P_t_r is a pointer to
the X error event. The procedure _p_r_o_c should return an
integer value. If it returns 0 it means that _p_r_o_c handled
Tk 2
Tk_CreateErrorHandler(3T)k Library Procedures
the error completely and there is no need to take any other
action for the error. If it returns non-zero it means _p_r_o_c
was unable to handle the error.
If a value of NULL is specified for _p_r_o_c, all matching
errors will be ignored: this will produce the same result
as if a procedure had been specified that always returns 0.
If more than more than one handler matches a particular
error, then they are invoked in turn. The handlers will be
invoked in reverse order of creation: most recently
declared handler first. If any handler returns 0, then sub-
sequent (older) handlers will not be invoked. If no handler
returns 0, then Tk invokes X'es default error handler, which
prints an error message and aborts the program. If you wish
to have a default handler that deals with errors that no
other handler can deal with, then declare it first.
The X documentation states that ``the error handler should
not call any functions (directly or indirectly) on the
display that will generate protocol requests or that will
look for input events.'' This restriction applies to
handlers declared by Tk_CreateErrorHandler; disobey it at
your own risk.
Tk_DeleteErrorHandler may be called to delete a previously-
created error handler. The _h_a_n_d_l_e_r argument identifies the
error handler, and should be a value returned by a previous
call to Tk_CreateEventHandler.
A particular error handler applies to errors resulting from
protocol requests generated between the call to
Tk_CreateErrorHandler and the call to Tk_DeleteErrorHandler.
However, the actual callback to _p_r_o_c may not occur until
after the Tk_DeleteErrorHandler call, due to buffering in
the client and server. If an error event pertains to a pro-
tocol request made just before calling
Tk_DeleteErrorHandler, then the error event may not have
been processed before the Tk_DeleteErrorHandler call. When
this situation arises, Tk will save information about the
handler and invoke the handler's _p_r_o_c later when the error
event finally arrives. If an application wishes to delete
an error handler and know for certain that all relevant
errors have been processed, it should first call
Tk_DeleteErrorHandler and then call XSync; this will flush
out any buffered requests and errors, but will result in a
performance penalty because it requires communication to and
from the X server. After the XSync call Tk is guaranteed
not to call any error handlers deleted before the XSync
call.
Tk 3
Tk_CreateErrorHandler(3T)k Library Procedures
For the Tk error handling mechanism to work properly, it is
essential that application code never calls XSetErrorHandler
directly; applications should use only
Tk_CreateErrorHandler.
KEYWORDS
callback, error, event, handler
Tk 4